public class ConcurrentMapCacheManager extends java.lang.Object implements CacheManager, BeanClassLoaderAware
CacheManager
implementation that lazily builds ConcurrentMapCache
instances for each getCache(java.lang.String)
request. Also supports a 'static' mode where
the set of cache names is pre-defined through setCacheNames(java.util.Collection<java.lang.String>)
, with no
dynamic creation of further cache regions at runtime.
Note: This is by no means a sophisticated CacheManager; it comes with no
cache configuration options. However, it may be useful for testing or simple
caching scenarios. For advanced local caching needs, consider
JCacheCacheManager
,
EhCacheCacheManager
,
CaffeineCacheManager
.
ConcurrentMapCache
Modifier and Type | Field and Description |
---|---|
private boolean |
allowNullValues |
private java.util.concurrent.ConcurrentMap<java.lang.String,Cache> |
cacheMap |
private boolean |
dynamic |
private SerializationDelegate |
serialization |
private boolean |
storeByValue |
Constructor and Description |
---|
ConcurrentMapCacheManager()
Construct a dynamic ConcurrentMapCacheManager,
lazily creating cache instances as they are being requested.
|
ConcurrentMapCacheManager(java.lang.String... cacheNames)
Construct a static ConcurrentMapCacheManager,
managing caches for the specified cache names only.
|
Modifier and Type | Method and Description |
---|---|
protected Cache |
createConcurrentMapCache(java.lang.String name)
Create a new ConcurrentMapCache instance for the specified cache name.
|
Cache |
getCache(java.lang.String name)
Return the cache associated with the given name.
|
java.util.Collection<java.lang.String> |
getCacheNames()
Return a collection of the cache names known by this manager.
|
boolean |
isAllowNullValues()
Return whether this cache manager accepts and converts
null values
for all of its caches. |
boolean |
isStoreByValue()
Return whether this cache manager stores a copy of each entry or
a reference for all its caches.
|
private void |
recreateCaches() |
void |
setAllowNullValues(boolean allowNullValues)
Specify whether to accept and convert
null values for all caches
in this cache manager. |
void |
setBeanClassLoader(java.lang.ClassLoader classLoader)
Callback that supplies the bean
class loader to
a bean instance. |
void |
setCacheNames(java.util.Collection<java.lang.String> cacheNames)
Specify the set of cache names for this CacheManager's 'static' mode.
|
void |
setStoreByValue(boolean storeByValue)
Specify whether this cache manager stores a copy of each entry (
true
or the reference (false for all of its caches. |
private final java.util.concurrent.ConcurrentMap<java.lang.String,Cache> cacheMap
private boolean dynamic
private boolean allowNullValues
private boolean storeByValue
@Nullable private SerializationDelegate serialization
public ConcurrentMapCacheManager()
public ConcurrentMapCacheManager(java.lang.String... cacheNames)
public void setCacheNames(@Nullable java.util.Collection<java.lang.String> cacheNames)
The number of caches and their names will be fixed after a call to this method, with no creation of further cache regions at runtime.
Calling this with a null
collection argument resets the
mode to 'dynamic', allowing for further creation of caches again.
public void setAllowNullValues(boolean allowNullValues)
null
values for all caches
in this cache manager.
Default is "true", despite ConcurrentHashMap itself not supporting null
values. An internal holder object will be used to store user-level null
s.
Note: A change of the null-value setting will reset all existing caches, if any, to reconfigure them with the new null-value requirement.
public boolean isAllowNullValues()
null
values
for all of its caches.public void setStoreByValue(boolean storeByValue)
true
or the reference (false
for all of its caches.
Default is "false" so that the value itself is stored and no serializable contract is required on cached values.
Note: A change of the store-by-value setting will reset all existing caches, if any, to reconfigure them with the new store-by-value requirement.
public boolean isStoreByValue()
public void setBeanClassLoader(java.lang.ClassLoader classLoader)
BeanClassLoaderAware
class loader
to
a bean instance.
Invoked after the population of normal bean properties but
before an initialization callback such as
InitializingBean's
InitializingBean.afterPropertiesSet()
method or a custom init-method.
setBeanClassLoader
in interface BeanClassLoaderAware
classLoader
- the owning class loaderpublic java.util.Collection<java.lang.String> getCacheNames()
CacheManager
getCacheNames
in interface CacheManager
@Nullable public Cache getCache(java.lang.String name)
CacheManager
getCache
in interface CacheManager
name
- the cache identifier (must not be null
)null
if none foundprivate void recreateCaches()
protected Cache createConcurrentMapCache(java.lang.String name)
name
- the name of the cache